package com.jzo2o.customer.controller.worker;


import cn.hutool.core.bean.BeanUtil;
import com.jzo2o.common.utils.UserContext;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/worker/bank-account")
@RequiredArgsConstructor
public class BankAccountController {


    private final IBankAccountService bankAccountService;

    //服务端设置银行账户
    @GetMapping("/currentUserBankAccount")
    public BankAccountResDTO currentUserBankAccount() {
        Long id = UserContext.getCurrentUser().getId();
        BankAccount bankAccount = bankAccountService.getById(id);
        return BeanUtil.toBean(bankAccount, BankAccountResDTO.class);

    }

    //新增或更新银行账号信息
    @PostMapping
    public BankAccountResDTO saveOrUpdate(@RequestBody BankAccountUpsertReqDTO bankAccountUpsertReqDTO) {
        return bankAccountService.addOrUpdate(bankAccountUpsertReqDTO);
    }

}
